package cn.basic.social.api.dingtalk.channel.internal.request;

import cn.basic.social.api.CommonConstants;
import cn.basic.social.api.dingtalk.BaseDingRequest;
import cn.basic.social.api.dingtalk.channel.internal.response.InternalGetUserInfoResponse;
import cn.basic.social.api.exception.ApiRuleException;
import cn.basic.social.api.utils.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName InternalGetUserInfoRequest
 * @Description 获取用户通讯录个人信息请求
 * https://open.dingtalk.com/document/orgapp/dingtalk-retrieve-user-information?spm=ding_open_doc.document.0.0.38e81a0dKnvhmy
 * @Author yk.zlf
 * @Date 2023/10/20 14:02
 */
public class InternalGetUserInfoRequest extends BaseDingRequest<InternalGetUserInfoResponse> implements Serializable {

    private final String requestUrl = "https://api.dingtalk.com/v1.0/contact/users/";
    private String topHttpMethod = CommonConstants.HTTP_METHOD_GET;
    private String topContentType = "application/json";

    /**
     * 用户的unionId
     * 如需获取当前授权人的信息，unionId参数可以传me
     */
    private String unionId;

    public InternalGetUserInfoRequest() {
    }

    public InternalGetUserInfoRequest(String unionId) {
        this.unionId = unionId;
    }

    public String getUnionId() {
        return unionId;
    }

    public void setUnionId(String unionId) {
        this.unionId = unionId;
    }

    @Override
    public String getTopHttpMethod() {
        return this.topHttpMethod;
    }

    @Override
    public void setTopHttpMethod(String topHttpMethod) {
        this.topHttpMethod = topHttpMethod;
    }

    @Override
    public Map<String, String> getTextParams() {
        Map<String, String> params = new HashMap<>();
        params.put("unionId", this.unionId);
        return params;
    }

    @Override
    public Class<InternalGetUserInfoResponse> getResponseClass() {
        return InternalGetUserInfoResponse.class;
    }

    @Override
    public void check() throws ApiRuleException {
        if (StringUtils.isBlank(this.unionId)) {
            throw new ApiRuleException("-1", "获取用户通讯录个人信息失败，缺少必要参数：unionId");
        }
    }

    @Override
    public String getTopContentType() {
        return this.topContentType;
    }

    @Override
    public void setTopContentType(String topContentType) {
        this.topContentType = topContentType;
    }

    @Override
    public String getRequestUrl() {
        return this.requestUrl + unionId;
    }
}
